/*
 * @file cuda_utilities.h
 * @Brief cuda utilities
 * @author Wei Chen
 *
 * This file is part of Physika, a versatile physics simulation library.
 * Copyright (C) 2013- Physika Group.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License v2.0.
 * If a copy of the GPL was not distributed with this file, you can obtain one at:
 * http://www.gnu.org/licenses/gpl-2.0.html
 *
 */

#pragma once
#include <cassert>
#include <cstdio>
#include <cuda_runtime.h>

namespace PhysLeo{

#ifdef NDEBUG
#define cudaCheck(x) {x;}
#define synchronCheck {}
#else
#define cudaCheck(x) { cudaError_t err = x; if (err != cudaSuccess) { printf("Cuda error: %d in %s at %s:%d\n", err, #x, __FILE__, __LINE__); printf("Cuda status: %s\n", cudaGetErrorString( cudaGetLastError() ) ); assert(0);} }
#define synchronCheck {cudaDeviceSynchronize();cudaError_t err =cudaGetLastError();if (err != cudaSuccess) { printf("Cuda error: %d : %s at %s:%d\n", err,cudaGetErrorString(err) , __FILE__, __LINE__); assert(0);} }
#endif

}// end of namespace Physika
